package org.cs.mgr.before.ctl;

import java.util.List;
import java.util.Map;

import org.cs.mgr.before.dao.IGoodsSpecificationDao;
import org.cs.mgr.before.model.Goods;
import org.cs.mgr.before.service.IGoodsService;
import org.cs.mgr.before.service.IGoodsSpecificationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.alibaba.fastjson.JSONObject;

/**
 * @Author:guo
 
 */
@Controller
@RequestMapping("/reception")
public class ShopCtl {
	@Autowired
	IGoodsService igoodsService;
	@Autowired
	IGoodsSpecificationService   igoodsspecificationservice;
	
	
	
	
    //跳转购物车页面 
    @RequestMapping("/shopcart")
    public String shopcart(String id,ModelMap mm){     //参数是当前商品的id
    	Goods good = igoodsService.getGood(id);           //通过goods的id查goods表
        mm.put("goodId", good.getID());
        return "jsp/shop";
    }

    //立即购买，确定,接收参数，跳转确认订单页面
    @RequestMapping("/buyimmediately")
    @ResponseBody
  //参数id 是商品的id，目的是为了正常返回页面，参数gsid是被选中的商品规格的id，amount是商品的数量
    public String buyimmediately(String id,String gs_id,String amount){  
    	//通过goods的id查goods表
    	Goods good = igoodsService.getGood(id);                 
        //通过gs_id查商品规格表,返回商品规格表一条记录
        List<Map<String, Object>> goodsSpecificationOne = igoodsspecificationservice.getGoodsSpecificationOne(gs_id);
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("good", good);
        jsonObject.put("gsOne", goodsSpecificationOne.get(0));       
        return jsonObject.toJSONString();
    }
    
    
    
  
}
